home *** CD-ROM | disk | FTP | other *** search
/ CU Amiga Super CD-ROM 17 / CU Amiga Magazine's Super CD-ROM 17 (1997)(EMAP Images)(GB)[!][issue 1997-12].iso / CUCD / Programming / DiceSource / src / patch / amiga.c next >
C/C++ Source or Header  |  1997-09-09  |  3KB  |  159 lines

  1. /*
  2.  *    (c)Copyright 1992-1997 Obvious Implementations Corp.  Redistribution and
  3.  *    use is allowed under the terms of the DICE-LICENSE FILE,
  4.  *    DICE-LICENSE.TXT.
  5.  */
  6.  
  7. /*
  8.  *  AMIGA replacement routines
  9.  */
  10.  
  11. #include <stdio.h>
  12. #include <stdlib.h>
  13. #include <string.h>
  14. #include <sys/stat.h>
  15. #include <libraries/dos.h>
  16. #include <libraries/dosextens.h>
  17.  
  18. /*
  19.  *  Uses PT: for 'patch temp'
  20.  */
  21.  
  22. static long tfid;
  23.  
  24. char *
  25. mktemp(buf)
  26. char *buf;
  27. {
  28.     char *base = buf;
  29.     buf += strlen(buf);
  30.     sprintf(buf, "%06x%d", FindTask(NULL) >> 8, tfid++);
  31.     return(base);
  32. }
  33.  
  34. int
  35. chmod(name, mode)
  36. char *name;
  37. int mode;
  38. {
  39.     return(0);
  40. }
  41.  
  42. char *gettmpenv(const char *);
  43. char *getenv(const char *);
  44.  
  45. char *
  46. gettmpenv(id)
  47. const char *id;
  48. {
  49.     static char *buf;
  50.     static char *res = NULL;
  51.     long fh;
  52.     long len;
  53.  
  54.     buf = malloc(strlen(id) + 8);
  55.     sprintf(buf, "ENV:%s", id);
  56.     fh = Open(buf, 1005);
  57.     free(buf);
  58.     if (fh) {
  59.     Seek(fh, 0L, 1);
  60.     len = Seek(fh, 0L, -1);
  61.     if (len < 0) {
  62.         Close(fh);
  63.         return(NULL);
  64.     }
  65.     if (res)
  66.         free(res);
  67.     res = malloc(len + 1);
  68.     Read(fh, res, len);
  69.     Close(fh);
  70.     res[len] = 0;
  71.     return(res);
  72.     }
  73.     return(NULL);
  74. }
  75.  
  76. char *
  77. getenv(id)
  78. const char *id;
  79. {
  80.     char *res = gettmpenv(id);
  81.     char *perm = NULL;
  82.  
  83.     if (res)
  84.     perm = strdup(res);
  85.     return(perm);
  86. }
  87.  
  88. int
  89. fstat(fd, stat)
  90. int fd;
  91. struct stat *stat;
  92. {
  93.     long pos;
  94.  
  95.     setmem(stat, sizeof(struct stat), 0);
  96.     pos = lseek(fd, 0L, 1);
  97.     stat->st_size = lseek(fd, 0L, 2);
  98.     stat->st_mode = S_IFREG;
  99.     lseek(fd, pos, 0);
  100.     return(0);
  101. }
  102.  
  103. int
  104. stat(name, stat)
  105. char *name;
  106. struct stat *stat;
  107. {
  108.     BPTR lock = Lock(name, SHARED_LOCK);
  109.     __aligned struct FileInfoBlock fib;
  110.  
  111.     setmem(stat, sizeof(struct stat), 0);
  112.     if (lock == NULL)
  113.     return(-1);
  114.     Examine(lock, &fib);
  115.     UnLock(lock);
  116.     stat->st_size = fib.fib_Size;
  117.     stat->st_ino = (long)((struct FileLock *)BADDR(lock))->fl_Key;
  118.     stat->st_dev = (long)((struct FileLock *)BADDR(lock))->fl_Task;
  119.     stat->st_mode = (fib.fib_DirEntryType > 0) ? S_IFDIR : S_IFREG;
  120.     return(0);
  121. }
  122.  
  123. link(a, b)
  124. char *a, *b;
  125. {
  126.     return(-1);
  127. }
  128.  
  129. static char pnam[L_tmpnam];
  130. static char Cmd[256];
  131.  
  132. FILE *
  133. popen(cmd, modes)
  134. char *cmd;
  135. char *modes;
  136. {
  137.     tmpnam(pnam);
  138.     {
  139.     char *ptr;
  140.     if (ptr = strrchr(cmd, '/')) {
  141.         cmd = ptr + 1;
  142.     }
  143.     }
  144.     if (strnicmp(cmd, "ed", 2) == 0)
  145.     sprintf(Cmd, "u%s < %s", cmd, pnam);
  146.     else
  147.     sprintf(Cmd, "%s < %s", cmd, pnam);
  148.     return(fopen(pnam, modes));
  149. }
  150.  
  151. pclose(fi)
  152. FILE *fi;
  153. {
  154.     fclose(fi);
  155.     Execute(Cmd, NULL, NULL);
  156.     return(0);
  157. }
  158.  
  159.